package com.itheima.controller;

import com.itheima.pojo.entity.Emp;
import com.itheima.pojo.entity.Result;
import com.itheima.pojo.result.PageBean;
import com.itheima.pojo.utils.OssClientService;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;
import java.util.List;

/**
 * 员工管理Controller
 */
@RestController
@RequestMapping("/emps")
@Slf4j
public class EmpController {

    @Autowired
    private EmpService empService;
    @GetMapping
    public Result page(
            String name, Short gender,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            LocalDate begin,
            LocalDate end) {
        log.info("分页查询,参数:{},{},{},{},{},{}", page, pageSize, name, gender, begin, end);
        PageBean pageBean = empService.page(page, pageSize, name, gender, begin, end);
        return Result.success(pageBean);
    }

    @DeleteMapping("/{ids}")
    public Result deleteList(@RequestParam List<Integer> ids) {
        log.info("批量删除操作,ids:{}", ids);
        empService.deleteList(ids);
        return Result.success();
    }
    @DeleteMapping
    public Result delete(Integer ids) {
        log.info("根据ID来删除员工信息,id:{}", ids);
        empService.delete(ids);
        return Result.success();
    }

    @PostMapping
    public Result save(@RequestBody Emp emp) {
        log.info("新增员工:{}", emp);
        empService.save(emp);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("根据ID来查询员工信息,id:{}", id);
        Emp emp = empService.getById(id);
        return Result.success(emp);
    }

    @PutMapping
    public Result update(@RequestBody Emp emp) {
        log.info("更新员工信息:{}", emp);
        empService.update(emp);
        return Result.success();
    }
}
